package mo.offer_special;

import java.util.Arrays;

public class L012 {

    public int pivotIndex(int[] nums) {
        int total = Arrays.stream(nums).sum();
        int sum = 0;
        //sum = total - sum - num[i] ==> 2 * sum + num[i] == total
        for (int i = 0; i < nums.length; i++) {
            if (2 * sum + nums[i] == total) {
                return i;
            } else {
                sum += nums[i];
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        L012 test = new L012();
        System.out.println(test.pivotIndex(new int[]{-1,-1,-1,1,1,1}));
    }
}
